﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Dracham.MapEditor.Textures;
using Dracham.MapEditor.Zones;

namespace Dracham.MapEditor.Maps
{
    public class ZoneTilePicureBox : PictureBox
    {
        private ZoneTile zoneTile;

        public ZoneTile ZoneTile
        {
            get
            {
                return this.zoneTile;
            }
            set
            {
                this.zoneTile = value;
                this.BackgroundImage = this.zoneTile.Background;
                this.DecorationImage = this.zoneTile.Decoration;
            }
        }

        new public Tile BackgroundImage
        {
            get
            {
                return this.zoneTile.Background;
            }
            set
            {
                this.zoneTile.Background = value;
                this.Image = value == null ? null : value.Image;

                if (this.zoneTile.Decoration != null)
                {
                    this.DecorationImage = this.zoneTile.Decoration;
                }
            }
        }

        public Tile DecorationImage
        {
            get
            {
                return this.zoneTile.Decoration;
            }
            set
            {
                if (value == null)
                {
                    this.zoneTile.Decoration = null;
                    this.BackgroundImage = this.zoneTile.Background;

                    return;
                }

                Image i;
                if (this.zoneTile.Background != null)
                {
                    i = (Image)this.zoneTile.Background.Image.Clone();
                }
                else
                {
                    i = new Bitmap(32, 32);
                }

                Graphics g = Graphics.FromImage(i);
                g.DrawImage(value.Image, new Point(0, 0));

                this.Image = i;
                this.zoneTile.Decoration = value;
            }
        }

        public ZoneTilePicureBox()
        {

        }
    }
}
